package com.ruoyi.application.service.impl;

import java.util.List;

import com.ruoyi.audit.domain.Audit;
import com.ruoyi.audit.mapper.AuditMapper;
import com.ruoyi.audit.service.IAuditService;
import com.ruoyi.common.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import org.springframework.stereotype.Service;
import com.ruoyi.application.mapper.ApplicationMapper;
import com.ruoyi.application.domain.Application;
import com.ruoyi.application.service.IApplicationService;

import javax.annotation.Resource;

/**
 * 用车申请Service业务层处理
 * 
 * @author ruoyi
 * @date 2025-07-08
 */
@Service
public class ApplicationServiceImpl implements IApplicationService 
{
    @Resource
    private ApplicationMapper applicationMapper;
    @Autowired
    private AuditMapper auditMapper;

    /**
     * 查询用车申请
     * 
     * @param id 用车申请主键
     * @return 用车申请
     */
    @Override
    public Application selectApplicationById(Long id)
    {
        return applicationMapper.selectApplicationById(id);
    }

    /**
     * 查询用车申请列表
     * 
     * @param application 用车申请
     * @return 用车申请
     */
    @Override
    public List<Application> selectApplicationList(Application application)
    {
        return applicationMapper.selectApplicationList(application);
    }

    /**
     * 新增用车申请
     * 
     * @param application 用车申请
     * @return 结果
     */
    @Override
    public int insertApplication(Application application)
    {
        application.setStatus("10");
        application.setCreateTime(DateUtils.getNowDate());
        return applicationMapper.insertApplication(application);
    }

    /**
     * 修改用车申请
     * 
     * @param application 用车申请
     * @return 结果
     */
    @Override
    public int updateApplication(Application application)
    {
        application.setUpdateTime(DateUtils.getNowDate());
        return applicationMapper.updateApplication(application);
    }

    /**
     * 批量删除用车申请
     * 
     * @param ids 需要删除的用车申请主键
     * @return 结果
     */
    @Override
    public int deleteApplicationByIds(Long[] ids)
    {
        return applicationMapper.deleteApplicationByIds(ids);
    }

    /**
     * 删除用车申请信息
     * 
     * @param id 用车申请主键
     * @return 结果
     */
    @Override
    public int deleteApplicationById(Long id)
    {
        return applicationMapper.deleteApplicationById(id);
    }

    @Override
    public void updateStatus(Long id) {
        Application application = new Application();
        application.setId(id);
        application.setStatus("20");
        applicationMapper.updateApplication(application);
        Audit audit = new Audit();
        audit.setApplicationId(id);
        audit.setAuditUserId(1L);
        audit.setAuditStatus("10");
        audit.setAuditSort(1);
        audit.setCreateTime(DateUtils.getNowDate());
        audit.setUpdateTime(DateUtils.getNowDate());
        auditMapper.insertAudit(audit);
    }
}
